package com.situ.web.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.situ.web.dao.IManagerDao;
import com.situ.web.util.JDBCUtil;
import com.situ.web.util.ModelConvertUtil;

public class ManagerDaoImpl implements IManagerDao {

	@Override
	public List<Map<String, Object>> findAllMap() {
		Connection connection = null;
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		List<Map<String, Object>> list = null;
		try {
			connection = JDBCUtil.getConnection();
			String sql = "SELECT s.id as s_id,s.name as s_name,b.name as b_name,c.name as c_name,c.credit as c_credit "
					+ "FROM student as s  INNER JOIN banji as b ON s.banji_id=b.id  "
					+ "INNER JOIN banji_course as bc on b.id=bc.banji_id "
					+ "INNER JOIN course as c ON bc.course_id=c.id;";
			preparedStatement = connection.prepareStatement(sql);
			resultSet = preparedStatement.executeQuery();
			list = ModelConvertUtil.converToList(resultSet);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

}
